#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
int x, y;
char arr[550][550];
int ans;
int xx[4] = { 0,1,-1,0 };
int yy[4] = { -1,0,0,1 };
void dfs(int x0, int y0)
{
	if (arr[x0][y0] == '*' || x0<1 || x0>x || y0<1 || y0>y)return;
	else {
		arr[x0][y0] = '*';
		for (int i = 0; i < 4; i++)dfs(x0 + xx[i], y0 + yy[i]);
	}
}

int main()
{
	cin >> x >> y;
	for (int i = 1; i <= x; i++) {
		cin >> arr[i] + 1;
	}
	for (int i = 1; i <= x; i++)
		if (arr[i][1] == '0')
			dfs(i, 1);
	for (int i = 1; i <= x; i++)
		if (arr[i][y] == '0')
			dfs(i, y);
	for (int j = 2; j < y; j++)
		if (arr[1][j] == '0')
			dfs(1, j);
	for (int j = 2; j < y; j++)
		if (arr[x][j] == '0')
			dfs(x, j);
	for (int i = 2; i < x; i++) {
		for (int j = 2; j < y; j++) {
			if (arr[i][j] == '0')ans++;
		}
	}
	cout << ans << endl;
	return 0;
}